#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <SDL2/SDL.h>

#define PIX_COUNT 1
#define W 255
#define H 127
SDL_Color colors[53] = {
    {117, 117, 117, 0},
    {39, 27, 143, 0},
    {0, 0, 171, 0},
    {71, 0, 159, 0},
    {143, 0, 119, 0},
    {171, 0, 19, 0},
    {167, 0, 0, 0},
    {127, 11, 0, 0},
    {67, 47, 0, 0},
    {0, 71, 0, 0},
    {0, 81, 0, 0},
    {0, 63, 23, 0},
    {27, 63, 95, 0},
    {188, 188, 188, 0},
    {0, 115, 239, 0},
    {35, 59, 239, 0},
    {131, 0, 243, 0},
    {191, 0, 191, 0},
    {231, 0, 91, 0},
    {219, 43, 0, 0},
    {203, 79, 15, 0},
    {139, 115, 0, 0},
    {0, 151, 0, 0},
    {0, 171, 0, 0},
    {0, 147, 59, 0},
    {0, 131, 139, 0},
    {0, 0, 0, 0},
    {255, 255, 255, 0},
    {63, 191, 255, 0},
    {95, 151, 255, 0},
    {167, 139, 253, 0},
    {247, 123, 255, 0},
    {255, 119, 183, 0},
    {255, 119, 99, 0},
    {255, 155, 59, 0},
    {243, 191, 63, 0},
    {131, 211, 19, 0},
    {79, 223, 75, 0},
    {88, 248, 152, 0},
    {0, 235, 219, 0},
    {255, 255, 255, 0},
    {171, 231, 255, 0},
    {199, 215, 255, 0},
    {215, 203, 255, 0},
    {255, 199, 255, 0},
    {255, 199, 219, 0},
    {255, 191, 179, 0},
    {255, 219, 171, 0},
    {255, 231, 163, 0},
    {227, 255, 163, 0},
    {171, 243, 191, 0},
    {179, 255, 207, 0},
    {159, 255, 243, 0}};
//
typedef struct
{
    unsigned char x, y, c;
} Pix;

//测试一下绘图指令
//
int main(int argc, char const *argv[])
{
    time_t t;
    srand((unsigned)time(&t));

    FILE *file = fopen("color.pix", "wb");
    if (!file)
    {
        return 1;
    }
    for (unsigned char i = 0; i < W; i++)
    {
        for (unsigned char j = 0; j < H; j++)
        {
            unsigned char c = rand() * 52;
            printf("<p style=\"color:rgb(%d,%d,%d)\">COLOR</p>\n", colors[c].r, colors[c].g, colors[c].b);
            Pix p = {i, j, c};
            fwrite(&p.x, 1, PIX_COUNT, file);
            fwrite(&p.y, 1, PIX_COUNT, file);
            fwrite(&p.c, 1, PIX_COUNT, file);
        }
    }
    fclose(file);
    return 0;
}
